package cn.jdy.authority.admin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.jdy.authority.entity.User;
import cn.jdy.authority.service.UserColumnService;
import cn.jdy.authority.service.UserService;
import cn.jdy.framework.log.BaseLog;
import cn.jdy.platform.entity.ConfValue;
import cn.jdy.platform.service.ConfService;

/**
 * @desc 用户栏目管理控制类 
 * @author nignqian
 * @date   2016-9-13 11:00
 */
@Controller
@RequestMapping("/userColumn")
public class UserColumnCtrl {

	@Autowired
	protected HttpServletRequest request;
	@Autowired
	protected HttpSession session;
	@Autowired
	private UserService userService;
	@Autowired
	private UserColumnService userColumnService;
	@Autowired
	private ConfService confService;
	
	
	/**
	 * 初始系统用户列表
	 *
	 * @description: 将所有的角色信息取出来
	 */
	@RequestMapping("initUser")
	@ResponseBody
	public Map<String, Object> initUser() {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			List<User> userList = userService.find("status","01");
			map.put("msg", "success");
			map.put("userList", userList);
		} catch(Exception e) {
			map.put("msg", "error");
			BaseLog.e(this.getClass(), "initUser初始化用户信息失败", e);
		}
		return map;
	}


	
	@RequestMapping("/listColumn")
	@ResponseBody
	public Map<String, Object> listColumn() {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		List<ConfValue> list = new ArrayList<ConfValue>();
		try {
			// 获得系统所有菜单
			list = userColumnService.listColumn(21,0);
			jsonMap.put("Rows", list);
		} catch(Exception e) {
			BaseLog.e(this.getClass(), "listColumn 显示系统所有文章栏目信息有误", e);
		}
		return jsonMap;
	}
	
	
	@RequestMapping("/allColumn")
	@ResponseBody
	public Map<String, Object> allColumn() {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		List<ConfValue> list = new ArrayList<ConfValue>();
		try {
			// 获得系统所有菜单
			list = userColumnService.xzgajListColumn(21);
			jsonMap.put("Rows", list);
		} catch(Exception e) {
			BaseLog.e(this.getClass(), "allColumn 显示系统所有文章栏目信息有误", e);
		}
		return jsonMap;
	}
	
	
	@RequestMapping("/listDjColumn")
	@ResponseBody
	public Map<String, Object> listDjColumn() {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		List<ConfValue> list = new ArrayList<ConfValue>();
		try {
			// 获得系统所有菜单
			list = userColumnService.djgajListColumn(21);
			jsonMap.put("Rows", list);
		} catch(Exception e) {
			BaseLog.e(this.getClass(), "listDjColumn 显示系统所有文章栏目信息有误", e);
		}
		return jsonMap;
	}
	
	@RequestMapping("/listLhkColumn")
	@ResponseBody
	public Map<String, Object> listLhkColumn() {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		List<ConfValue> list = new ArrayList<ConfValue>();
		try {
			// 获得系统所有菜单
			list = userColumnService.lhkgajListColumn(21);
			jsonMap.put("Rows", list);
		} catch(Exception e) {
			BaseLog.e(this.getClass(), "listDjColumn 显示系统所有文章栏目信息有误", e);
		}
		return jsonMap;
	}
	

	@RequestMapping("/listXdColumn")
	@ResponseBody
	public Map<String, Object> listXdColumn() {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		List<ConfValue> list = new ArrayList<ConfValue>();
		try {
			list = confService.xdgajListColumn(21);
			jsonMap.put("Rows", list);
		} catch(Exception e) {
			BaseLog.e(this.getClass(), "listXdColumn 显示系统所有文章栏目信息有误", e);
		}
		return jsonMap;
	}
	
	@RequestMapping("/listdzddColumn")
	@ResponseBody
	public Map<String, Object> listdzddColumn() {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		List<ConfValue> list = new ArrayList<ConfValue>();
		try {
			// 获得系统所有菜单
			list = userColumnService.dzddListColumn(21);
			jsonMap.put("Rows", list);
		} catch(Exception e) {
			BaseLog.e(this.getClass(), "listDjColumn 显示系统所有文章栏目信息有误", e);
		}
		return jsonMap;
	}
	
	/**
	 * 用户文章栏目管理
	 *
	 * @param userid 用户ID 
	 * @return Map<String, Object>
	 */
	@RequestMapping("/findUserColumn")
	@ResponseBody
	public Map<String, Object> findUserColumn(String userid) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		try {
			// 获得当前用户已存在的文章栏目权限
			List<String> list = userColumnService.findUserColumn(userid);
			jsonMap.put("userColumn", list);
		} catch(Exception e) {
			BaseLog.e(this.getClass(), "findRoleMenu 用户文章栏目管理有误", e);
		}
		return jsonMap;
	}
	
	/**
	 * 添加用户文章栏目权限
	 *
	 * @param userid 用户ID
	 * @param cid 文章栏目ID ningqian 2016-09-13
	 * @return Map<String, Object>
	 */
	@RequestMapping("/addUserColumn")
	@ResponseBody
	public Map<String, Object> addUserColumn(String userid, String cid) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		try {
			userColumnService.addUserColumn(userid, cid);
			jsonMap.put("statusCode", 200);
		} catch(Exception e) {
			jsonMap.put("statusCode", 500);
			BaseLog.e(this.getClass(), "addRoleMenu 添加角色权限有误", e);
		}
		return jsonMap;
	}

	/**
	 * 获取所有签收单位
	 * @return
	 */
	@RequestMapping("/listDjQsdw")
	@ResponseBody
	public Map<String, Object> listDjQsdw() {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		List<ConfValue> list = new ArrayList<ConfValue>();
		try {
			// 获得系统所有签收单位
			list = confService.queryByType(72,null);
			jsonMap.put("dataList", list);
		} catch(Exception e) {
			BaseLog.e(this.getClass(), "listDjColumn 获取系统所有签收单位信息有误", e);
		}
		return jsonMap;
	}
	
}
